<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="产品编码" prop="rootCode">
        <el-input
          v-model="queryParams.rootCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="物料名称" prop="chinaName">
        <el-input
          v-model="queryParams.chinaName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="别名" prop="asName">
        <el-input
          v-model="queryParams.asName"
          placeholder="请输入别名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="bom名称" prop="bomName" label-width="70px">
        <el-input
          v-model="queryParams.bomName"
          placeholder="请输入bom名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="bom版本" prop="bomVar">
        <el-input
          v-model="queryParams.bomVar"
          placeholder="请输入bom版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="父项编码" prop="parentId">
        <el-input
          v-model="queryParams.parentId"
          placeholder="请输入父项编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="父项目版本" prop="fatherPartvar">
        <el-input
          v-model="queryParams.fatherPartvar"
          placeholder="请输入父项目版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="物料编码" prop="partId">
        <el-input
          v-model="queryParams.partId"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="层次号" prop="assembLelevel">
        <el-input
          v-model="queryParams.assembLelevel"
          placeholder="请输入层次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="物料版本" prop="partVar">
        <el-input
          v-model="queryParams.partVar"
          placeholder="请输入物料版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="数量" prop="counts">
        <el-input
          v-model="queryParams.counts"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="年度" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入年度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期间" prop="moth">
        <el-input
          v-model="queryParams.moth"
          placeholder="请输入期间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="无税单价" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入无税单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="含税单价" prop="taxPrice">
        <el-input
          v-model="queryParams.taxPrice"
          placeholder="请输入含税单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市场价格" prop="marketPrice">
        <el-input
          v-model="queryParams.marketPrice"
          placeholder="请输入市场价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市场价格(含税)" prop="marktaxPrice">
        <el-input
          v-model="queryParams.marktaxPrice"
          placeholder="请输入市场价格(含税)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="直接人工" prop="workFee">
        <el-input
          v-model="queryParams.workFee"
          placeholder="请输入直接人工"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="天然气" prop="gasFee">
        <el-input
          v-model="queryParams.gasFee"
          placeholder="请输入天然气"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电费" prop="elecFee">
        <el-input
          v-model="queryParams.elecFee"
          placeholder="请输入电费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制造费用" prop="makeFee">
        <el-input
          v-model="queryParams.makeFee"
          placeholder="请输入制造费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合计" prop="totalFee">
        <el-input
          v-model="queryParams.totalFee"
          placeholder="请输入合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间戳" prop="nodeTimesTamp">
        <el-date-picker clearable
          v-model="queryParams.nodeTimesTamp"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择时间戳">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="价格时间" prop="priceTime">
        <el-date-picker clearable
          v-model="queryParams.priceTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择价格时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="marks">
        <el-input
          v-model="queryParams.marks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基期" prop="partDate">
        <el-date-picker clearable
          v-model="queryParams.partDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择基期">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
	    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:bomCost:export']"
        >导出</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:bomCost:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
        >展开/折叠</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="bomCostList"
      row-key="id"
      :default-expand-all="isExpandAll"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      :load="getChildrens"
      lazy
      style="width: 100%"
      height="calc(100vh - 85px)"
      :row-class-name="tableRowClassName"
    >
      <!-- <el-table-column label="bom名称" align="center" prop="bomName" min-width="430px" /> -->
      <el-table-column label="物料名称" header-align="center" prop="chinaName" min-width="220px" fixed/>
      <el-table-column label="类型" prop="type" align="center">
        <template slot-scope="scope" >
          <dict-tag :options="dict.type.mtr_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      
      <el-table-column label="别名" align="center" prop="asName" />
      
      <!-- <el-table-column label="bom版本" align="center" prop="bomVar" /> -->
      <el-table-column label="父项编码" align="center" prop="parentId" min-width="150px" />
      <!-- <el-table-column label="父项目版本" align="center" prop="fatherPartvar" /> -->
      <el-table-column label="物料编码" align="center" prop="partId" min-width="150px"/>
      <!-- <el-table-column label="层次号" align="center" prop="assembLelevel" /> -->
      <!-- <el-table-column label="物料版本" align="center" prop="partVar" /> -->
      <el-table-column label="数量" align="center" prop="counts" :formatter="matter" />
      
      <el-table-column label="材料价格" align="center" prop="price" min-width="100px" :formatter="matter" />
      <!-- <el-table-column label="含税单价" align="center" prop="taxPrice" /> -->
      <el-table-column label="市场价格" align="center" prop="marketPrice" min-width="100px" :formatter="matter" />
      <!-- <el-table-column label="市场价格(含税)" align="center" prop="marktaxPrice" min-width="110px" /> -->
      <el-table-column label="成品价格" align="center" prop="productPrice" min-width="100px" :formatter="matter" />
      <el-table-column label="直接人工" align="center" prop="workFee" :formatter="matter" />
      <el-table-column label="天然气" align="center" prop="gasFee" :formatter="matter" />
      <el-table-column label="电费" align="center" prop="elecFee" :formatter="matter" />
      <el-table-column label="制造费用" align="center" prop="makeFee" :formatter="matter" />
      <el-table-column label="标准成本" align="center" prop="stTotalFee" min-width="90px" :formatter="matter" />
      <el-table-column label="市场成本" align="center" prop="totalFee" min-width="90px" :formatter="matter" />
      <!-- <el-table-column label="合计(测算)" align="center" prop="totalFee" min-width="90px" :formatter="rounding"  /> -->
      <!-- <el-table-column label="毛利率(%)" align="center" prop="grossProfitRate" /> -->
      <!-- <el-table-column label="标准销售价格" align="center" prop="stSalePrice" /> -->
      <!-- <el-table-column label="销售价格" align="center" prop="salePrice" /> -->
      <!-- <el-table-column label="时间戳" align="center" prop="nodeTimesTamp" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nodeTimesTamp, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="价格时间" align="center" prop="priceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.priceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="marks" />
      <el-table-column label="基期" align="center" prop="partDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.partDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:bomCost:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAdd(scope.row)"
            v-hasPermi="['system:bomCost:add']"
          >新增</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:bomCost:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改bom模型对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="物料名称" prop="chinaName">
          <el-input v-model="form.chinaName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="别名" prop="asName">
          <el-input v-model="form.asName" placeholder="请输入别名" />
        </el-form-item>
        <!-- <el-form-item label="bom名称" prop="bomName">
          <el-input v-model="form.bomName" placeholder="请输入bom名称" />
        </el-form-item>
        <el-form-item label="bom版本" prop="bomVar">
          <el-input v-model="form.bomVar" placeholder="请输入bom版本" />
        </el-form-item>
        <el-form-item label="父项编码" prop="parentId">
          <treeselect v-model="form.parentId" :options="bomCostOptions" :normalizer="normalizer" placeholder="请选择父项编码" />
        </el-form-item>
        <el-form-item label="父项目版本" prop="fatherPartvar">
          <el-input v-model="form.fatherPartvar" placeholder="请输入父项目版本" />
        </el-form-item>
        <el-form-item label="物料编码" prop="partId">
          <el-input v-model="form.partId" placeholder="请输入物料编码" />
        </el-form-item>
        <el-form-item label="层次号" prop="assembLelevel">
          <el-input v-model="form.assembLelevel" placeholder="请输入层次号" />
        </el-form-item>
        <el-form-item label="物料版本" prop="partVar">
          <el-input v-model="form.partVar" placeholder="请输入物料版本" />
        </el-form-item>
        <el-form-item label="数量" prop="counts">
          <el-input v-model="form.counts" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="年度" prop="year">
          <el-input v-model="form.year" placeholder="请输入年度" />
        </el-form-item>
        <el-form-item label="期间" prop="moth">
          <el-input v-model="form.moth" placeholder="请输入期间" />
        </el-form-item> -->
        <el-form-item label="材料价格" prop="price" >
          <el-input v-model="form.price" placeholder="请输入材料单价" />
        </el-form-item>
        <!-- <el-form-item label="含税单价" prop="taxPrice">
          <el-input v-model="form.taxPrice" placeholder="请输入含税单价" />
        </el-form-item> -->
        <el-form-item label="市场价格" prop="marketPrice">
          <el-input v-model="form.marketPrice" placeholder="请输入市场价格" />
        </el-form-item>
        <!-- <el-form-item label="市场价格(含税)" prop="marktaxPrice">
          <el-input v-model="form.marktaxPrice" placeholder="请输入市场价格(含税)" />
        </el-form-item> -->
        <el-form-item label="直接人工" prop="workFee">
          <el-input v-model="form.workFee" placeholder="请输入直接人工" />
        </el-form-item>
        <el-form-item label="天然气" prop="gasFee">
          <el-input v-model="form.gasFee" placeholder="请输入天然气" />
        </el-form-item>
        <el-form-item label="电费" prop="elecFee">
          <el-input v-model="form.elecFee" placeholder="请输入电费" />
        </el-form-item>
        <el-form-item label="制造费用" prop="makeFee">
          <el-input v-model="form.makeFee" placeholder="请输入制造费用" />
        </el-form-item>
        <!-- <el-form-item label="标准合计" prop="stTotalFee">
          <el-input v-model="form.stTotalFee" placeholder="请输入标准合计" />
        </el-form-item>
        <el-form-item label="合计" prop="totalFee">
          <el-input v-model="form.totalFee" placeholder="请输入合计" />
        </el-form-item>
        <el-form-item label="毛利率" prop="grossProfitRate">
          <el-input v-model="form.grossProfitRate" placeholder="请输入毛利率" @input="limitInput($event, '你的参数')">
            <i slot="suffix" style="font-style:normal;margin-right: 10px;">%</i>
          </el-input>
        </el-form-item>
        <el-form-item label="销售价格" prop="salePrice">
          <el-input v-model="form.salePrice" placeholder="请输入销售价格" />
        </el-form-item>
        <el-form-item label="时间戳" prop="nodeTimesTamp">
          <el-date-picker clearable
            v-model="form.nodeTimesTamp"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择时间戳">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="价格时间" prop="priceTime">
          <el-date-picker clearable
            v-model="form.priceTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择价格时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="marks">
          <el-input v-model="form.marks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="基期" prop="partDate">
          <el-date-picker clearable
            v-model="form.partDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择基期">
          </el-date-picker>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style>
  .el-table .warning-row {
    background: rgb(250, 244, 232);
  }

  .el-table .success-row {
    background: #eff6ec;
  }

  .el-table .danger-row {
    background: #f8e8e8;
  }

  .el-table .info-row {
    background: #95979a;
  }

  .el-table .barand-row {
    background: #eff8fcda;
  }
</style>

<script>
import { listBomCost, getBomCost, delBomCost, addBomCost, updateBomCost, getroot, getchildren, handleExport} from "@/api/factory/bom/bomCost";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "BomCost",
  dicts: ['mtr_type'],
  components: {
    Treeselect
  },
  data() {
    var validatePwd = (rule,value,callback) => {
                // 定义验证规则
                var reg = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$)([^\u4e00-\u9fa5\s]){6,20}$/;
                // 进行校验判断与提示
                let aa = ('' + value) // 第一步：转成字符串
        .replace(/[^\d^\.]+/g, '') // 第二步：把不是数字，不是小数点的过滤掉
        .replace(/^0+(\d)/, '$1') // 第三步：第一位0开头，0后面为数字，则过滤掉，取后面的数字
        .replace(/^\./, '0.') // 第四步：如果输入的第一位为小数点，则替换成 0. 实现自动补全
        .match(/^\d{0,2}(\.?\d{0,2})/g)[0] || '' // 第五步：最终匹配得到结果 以数字开头，只有一个小数点，	而且小数点后面只能有0到2位小数
        // 是个数字
        if(Number(aa)){
            // 小于100大于0正确
          if(0<Number(aa)&&Number(aa)<100){
            console.log(1,aa)
            this.form[name] = aa
            callback();
          }else{
            // 大于100直接将第三个删掉替换为前两个字符组。触发字符100.25等
            console.log(2,aa)
            // this.zzbds = aa.splice(3,1)
            this.form[name] = aa.replace(/(.{2})./g,"$1")
            callback(new Error("请输入0-100之间的数字"));
          }
        }else{ // 不是个数，比如abd、0......等，原因是上面的判断覆盖了一部分正则校验
          if(aa != '0.'){
            // 不是0.开头的，比如字母等直接替换为空。触发字符abds等
            this.form[name] = ''
            console.log('zm',aa)
            callback(new Error("请输入0-100之间的数字"));
          }else{
            // 是0.开头的换为0.，触发字符0......等
            this.form[name] = aa
            console.log('sm',aa)
            callback(new Error("请输入0-100之间的数字"));
          }
        }


            //     if (value==''||value==undefined||value==null){
            //         callback(new Error("请填写密码！"));
            //     }
            //     else {
            //         if (!reg.test(value)){
            //             callback(new Error('6-20位英文字母、数字或者符号（除空格），且字母、数字和标点符号至少包含两种'));
            //         } else {
            //             callback();
            //         }
            //     }
            // };
            };
    return {
      maps: new Map(),
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // bom模型表格数据
      bomCostList: [],
      // bom模型树选项
      bomCostOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rootCode: null,
        type: null,
        chinaName: null,
        asName: null,
        bomName: null,
        bomVar: null,
        parentId: null,
        fatherPartvar: null,
        partId: null,
        assembLelevel: null,
        partVar: null,
        counts: null,
        year: null,
        moth: null,
        price: null,
        taxPrice: null,
        marketPrice: null,
        marktaxPrice: null,
        workFee: null,
        gasFee: null,
        elecFee: null,
        makeFee: null,
        stTotalFee: null,
        totalFee: null,
        grossProfitRate: null,
        salePrice: null,
        nodeTimesTamp: null,
        priceTime: null,
        marks: null,
        partDate: null,
        rootCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        grossProfitRate: [
          { required: true, validatePwd: true, validator: validatePwd, trigger: "blur" }
        ],
        chinaName: [
          { required: true, message: "物料名称不能为空", trigger: "blur" }
        ],
        partId: [
          { required: true, message: "物料编码不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    // 添加千分符保留3为小数
    matter(row, column, cellValue) {
      if(null === cellValue) return '';
      cellValue += ''
      if (!cellValue.includes('.')) cellValue += '.'
      return parseFloat(cellValue).toFixed(3).replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
        return $1 + ','
      }).replace(/\.$/, '')
    },

    tableRowClassName({row, rowIndex}) {
      let arr = row.seqnum.split(".")
      arr.length
      
        if (arr.length === 1) {
          return 'barand-row';
        } else if (arr.length === 2) {
          return 'success-row';
        } else if (arr.length === 3) {
          return 'warning-row';
        } else if (arr.length === 4) {
          return 'danger-row';
        } else if (arr.length === 5) {
          return 'info-row';
        }
        return '';
      },
  
    /** 查询bom模型列表 */
    getList() {
      this.loading = true;
      this.queryParams.parentId = 'root'
      getroot(this.queryParams).then(response => {
        this.bomCostList = response.rows.map((item, index) =>{
                 item.hasChildren = true;
                 return item
             })
             this.total = response.total;
             this.loading = false;
      });
      
    },

  getChildrens(tree,treeNode, resolve){
    this.queryParams.id = tree.id
    getchildren(this.queryParams).then((response) => {
      
        var data
        if(response.data.length&&response.data.length > 0){
            let data = response.data.map((item, index) =>{
              if(item.type === '0'){
                item.hasChildren = false;
              }else{
                item.hasChildren = true;
              }  
              return item
            })
            resolve(data)
        }else{
            tree.hasChildren = false
        }
    });
},


    // getList() {
    //   this.loading = true;
    //   listBomCost(this.queryParams).then(response => {
    //     console.log('返回结果',response.data);
    //     var bomlist = response.data;
    //     console.log('返回结果list',bomlist);
    //     this.bomCostList = bomlist;
    //     this.loading = false;
    //   });
    // },
   
    /** 转换bom模型数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.partId,
        label: node.chinaName,
        children: node.children
      };
    },
	/** 查询bom模型下拉树结构 */
    getTreeselect() {
      listBomCost().then(response => {
        this.bomCostOptions = [];
        const data = { partId: 0, chinaName: 'root', children: [] };
        data.children = this.handleTree(response.data, "partId", "parentId");
        this.bomCostOptions.push(data);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        chinaName: null,
        asName: null,
        bomName: null,
        bomVar: null,
        parentId: null,
        fatherPartvar: null,
        partId: null,
        assembLelevel: null,
        partVar: null,
        counts: null,
        year: null,
        moth: null,
        price: null,
        taxPrice: null,
        marketPrice: null,
        marktaxPrice: null,
        workFee: null,
        gasFee: null,
        elecFee: null,
        makeFee: null,
        stTotalFee: null,
        totalFee: null,
        grossProfitRate: null,
        salePrice: null,
        nodeTimesTamp: null,
        priceTime: null,
        marks: null,
        createTime: null,
        updateTime: null,
        partDate: null,
        rootCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.partId) {
        this.form.parentId = row.partId;
      } else {
        this.form.parentId = 0;
      }
      this.open = true;
      this.title = "添加bom模型";
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      if (row != null) {
        this.form.parentId = row.partId;
      }
      getBomCost(row.id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改bom模型";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBomCost(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBomCost(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除bom模型编号为"' + row.id + '"的数据项？').then(function() {
        return delBomCost(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
      /** 导出按钮操作 */
      handleExport() {
      this.download('system/bomCost/export', {
        ...this.queryParams
      }, `bomCost_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
